package com.demo;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class Main {

	public static void main(String[] args) {

		// ApplicationContext context=new ClassPathXmlApplicationContext(new
		// String[]{"spring.xml"});
		AbstractApplicationContext context = new FileSystemXmlApplicationContext(
				"spring.xml");
	         context.registerShutdownHook();  //shutdown hook with container...
	         
/*
		MyClass myClass = (MyClass) context.getBean("myClass");

		System.out.println(myClass);

		MyClass myClass1 = (MyClass) context.getBean("myClass");

		System.out.println(myClass1);

		System.out.println(myClass.getX());
		System.out.println(myClass == myClass1);*/

		/* MyPojo myPojo = context.getBean("myPojo",MyPojo.class); */

		/*MyPojo myPojo = context.getBean(MyPojo.class);
		System.out.println("myPojo " + myPojo);*/

		ServiceFactoryLocator factoryLocator = context.getBean(
				"serviceLocator", ServiceFactoryLocator.class);

		System.out.println(factoryLocator);
		System.out
				.println("==================================================");

		try {
			Class<?> class1 = Class.forName("com.demo.ServiceFactoryLocator");
			Constructor<?> constructor = class1.getDeclaredConstructor(new Class[0]);
			constructor.setAccessible(true);
			ServiceFactoryLocator myClass2 = (ServiceFactoryLocator) constructor
					.newInstance(new Object[0]);

			System.out.println("My class 2 :::: " + myClass2);

		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
